<template>
  <div>
    <div class="playList" v-show="showPlayList" @click="falsePlayList">
      <div class="playList-wrapper" @click.stop>
        <!--      内容部分-->
        <div class="playList-content">
          <div class="title">
            <span class="close" @click="falsePlayList">关闭</span>
            <span class="clear" @click="showConfirm">
              <i class="icon-clear"></i>
            </span>
          </div>
          <scroll :data="this.sequenceList()" class="list-content">
            <ul>
              <li class="item"
                  @click="selectItem(item,index)"
                  v-for="(item,index) in this.sequenceList()"
                  :key="index">
                <i class="current" :class="getIcon(item)"></i>
                <span class="text">{{item.name}}</span>
                <span class="icon-delete" @click.stop="deleteSong(item)"></span>
              </li>
            </ul>
          </scroll>
        </div>
      </div>
    </div>
    <Confirm ref="confirm" @sureClear="clearPlayList"></Confirm>
  </div>
</template>

<script type="text/ecmascript-6">
  import {mapGetters, mapMutations, mapActions} from 'vuex'
  import Confirm from 'base/confirm/confirm'
  import Scroll from 'base/scroll/scroll'

  export default {
    data () {
      return {
        showPlayList: false
      }
    },
    methods: {
      // 删除一首歌曲
      deleteSong (item) {
        this.deleteSong(item)
      },
      // 当前播放的歌曲前面带播放图标
      getIcon (item) {
        if (this.currentSong().id === item.id) {
          return 'icon-play'
        }
        return ''
      },
      // 播放选中的歌曲
      selectItem (item, index) {
        this.setCurrentIndex(index)
        this.setPlaying(true)
      },
      // 清除播放列表
      clearPlayList () {
        this.clearPlayList()
      },
      // 点击让此组件消失
      falsePlayList () {
        this.showPlayList = false
      },
      // 弹出确定框
      showConfirm () {
        this.$refs.confirm.show()
      },
      ...mapGetters([
        'sequenceList',
        'currentSong'
      ]),
      ...mapActions([
        'clearPlayList',
        'deleteSong'
      ]),
      ...mapMutations({
        setCurrentIndex: 'SET_CURRENT_INDEX',
        setPlaying: 'SET_PLAYING'
      })
    },
    components: {
      Confirm,
      Scroll
    }
  }
</script>

<style scoped lang="stylus">
  @import "~common/stylus/variable.styl"
  .playList
    position: fixed
    top: 0
    right: 0
    bottom: 0
    left: 0
    z-index: 200
    background-color: $color-background-d

    .playList-wrapper
      position: absolute
      bottom: 0
      left: 0
      width: 100%
      background-color: $color-highlight-background

      .playList-content
        max-height: 240px
        /*bottom: 0*/
        padding: 10px
        overflow: hidden

        .title
          line-height: 20px
          padding: 10px
          font-size: $font-size-medium
          color: $color-text-d

          .close, .clear
            display: inline-block
            width: 30px
            height: 20px
            padding: 5px

          .clear
            float: right

        .list-content
          max-height: 117px
          overflow: hidden

        .item
          display: flex
          align-items: center
          padding: 10px
          height: 10px
          overflow: hidden

          .current
            flex: 0 0 20px
            width: 20px
            color: $color-theme
            font-size: $font-size-small

          .text
            flex: 1
            no-wrap()
            font-size: $font-size-medium
            color: $color-text-d

          .icon-delete
            extend-click()
            font-size: $font-size-small
            color: $color-theme
</style>
